package com.example.admin.testdemo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.admin.testdemo.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Created by Administrator on 2017/12/2.
 */

public class MonitorListAdapter extends BaseAdapter{
    private Context context;
    private List<String> list;

    public MonitorListAdapter(Context context, List<String> list) {
        this.context = context;
        if(list==null){
            list=new ArrayList<>();
        }
        this.list = list;
    }



    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public String getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view==null){
            holder=new ViewHolder();
            view= LayoutInflater.from(context).inflate(R.layout.monitor_list_adapter,null);
            holder.name= (TextView) view.findViewById(R.id.btn_tv);
            view.setTag(holder);
        }else {
            holder= (ViewHolder) view.getTag();
        }
        holder.name.setText(list.get(position));
        return view;
    }




    class ViewHolder{
        public TextView name;

    }

}
